using DG.Tweening;
using DG.Tweening.Core;
using DG.Tweening.Plugins.Options;
using UnityEngine;

namespace NL.UIEffects
{
    public static class UIEffectExtend
    {
        public static TweenerCore<float, float, FloatOptions> DOFactor(this UIDissolve target, float endvalue, float duration)
        {
            if (target == null) return null;


            TweenerCore<float, float, FloatOptions> tweenerCore = DOTween.To(() => target.effectFactor, delegate (float factor)
            {
                target.effectFactor = factor;
            }, endvalue, duration);

            tweenerCore.SetTarget(target);

            return tweenerCore;
        }

        public static TweenerCore<float, float, FloatOptions> DOFactor_DissolveAmount(this Material target, float endvalue, float duration)
        {
            if (target == null) return null;


            TweenerCore<float, float, FloatOptions> tweenerCore = DOTween.To(() => target.GetFloat("_DissolveAmount"), delegate (float factor)
            {
                target.SetFloat("_DissolveAmount", factor);
            }, endvalue, duration);

            tweenerCore.SetTarget(target);

            return tweenerCore;
        }
    }
}

